﻿<Local:NavigationView
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="SeriesManager.View.FrameView"
    NavigationCacheMode="Required"
    RequestedTheme="{Binding Model.Theme}"
    xmlns:Local="using:SeriesManager.View"
    xmlns:Converter="using:SeriesManager.Converter"
    xmlns:Custom="using:WinRTFramework.Common">
    
    <Page.Resources>
        <Converter:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter" />
    </Page.Resources>
    
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid>
            <Grid.Background>
                <ImageBrush ImageSource="{Binding Background}" Opacity="0.55" Stretch="UniformToFill" />
            </Grid.Background>
            <Custom:CustomFrame x:Name="NavigationFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Local:EventToCommandBehavior.RoutedEvent="Navigated" Local:EventToCommandBehavior.Command="{Binding NavigatedCommand}"  />

            <AppBar Visibility="{Binding NavigationBarCanOpen, Converter={StaticResource BooleanVisibilityConverter}}" IsOpen="{Binding NavigationBarIsOpen, Mode=TwoWay}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Padding="6,6,6,0" Background="{ThemeResource AppBarBackgroundThemeBrush}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,6">
                        <Button Command="{Binding HomeCommand}" Style="{StaticResource ApplicationBarButtonStyle}">
                            <Grid>
                                <TextBlock FontFamily="Segoe UI Symbol" FontSize="40" Text="&#xE113;" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
                                <TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" x:Uid="SubscriptionHeader" FontSize="12" Foreground="White" Margin="6,4" />
                            </Grid>
                        </Button>

                        <Button Command="{Binding SearchBarCommand}" Style="{StaticResource ApplicationBarButtonStyle}">
                            <Grid>
                                <TextBlock FontFamily="Segoe UI Symbol" FontSize="40" Text="&#xE11A;" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
                                <TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" x:Uid="SearchButton" FontSize="12" Foreground="White" Margin="6,4" />
                            </Grid>
                        </Button>

                        <Button Command="{Binding SettingsCommand}" Style="{StaticResource ApplicationBarButtonStyle}">
                            <Grid>
                                <TextBlock FontFamily="Segoe UI Symbol" FontSize="40" Text="&#xE115;" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
                                <TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" x:Uid="SettingsButton" FontSize="12" Foreground="White" Margin="6,4" />
                            </Grid>
                        </Button>
                    </StackPanel>

                    <StackPanel x:Name="AirCommands" Orientation="Horizontal" Grid.Column="1" Grid.Row="0" Margin="0,0,0,6">
                        <Button Command="{Binding AirDayCommand}" Style="{StaticResource ApplicationBarButtonStyle}" Background="#4372AA">
                            <Grid>
                                <TextBlock FontFamily="Segoe UI Symbol" FontSize="52" Text="{Binding Model.AirDay.Count}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
                                <TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" x:Uid="DayButton" FontSize="12" Foreground="White" Margin="6,4" />
                            </Grid>
                        </Button>

                        <Button Command="{Binding AirWeekCommand}" Style="{StaticResource ApplicationBarButtonStyle}" Background="#4372AA">
                            <Grid>
                                <TextBlock FontFamily="Segoe UI Symbol" FontSize="52" Text="{Binding Model.AirWeek.Count}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
                                <TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" x:Uid="WeekButton" FontSize="12" Foreground="White" Margin="6,4" />
                            </Grid>
                        </Button>

                        <Button Command="{Binding AirMonthCommand}" Style="{StaticResource ApplicationBarButtonStyle}" Background="#4372AA">
                            <Grid>
                                <TextBlock FontFamily="Segoe UI Symbol" FontSize="52" Text="{Binding Model.AirMonth.Count}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
                                <TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" x:Uid="MonthButton" FontSize="12" Foreground="White" Margin="6,4" />
                            </Grid>
                        </Button>

                        <Button Command="{Binding AirYearCommand}" Style="{StaticResource ApplicationBarButtonStyle}" Background="#4372AA" Margin="0">
                            <Grid>
                                <TextBlock FontFamily="Segoe UI Symbol" FontSize="52" Text="{Binding Model.AirYear.Count}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
                                <TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" x:Uid="YearButton" FontSize="12" Foreground="White" Margin="6,4" />
                            </Grid>
                        </Button>
                    </StackPanel>
                </Grid>
            </AppBar>

            <Popup x:Name="popUp" IsOpen="{Binding SearchBarIsOpen, Mode=TwoWay}" HorizontalAlignment="Stretch" IsLightDismissEnabled="True" Opened="Popup_Opened">
                <StackPanel x:Name="popUpChild" Background="White" Height="auto">
                    <TextBlock Foreground="Black" x:Uid="SearchBarExplanation" TextWrapping="Wrap" FontSize="18.667" Margin="30,40,30,0" />
                    <SearchBox x:Name="searchBox" HorizontalAlignment="Stretch" FocusOnKeyboardInput="True" x:Uid="SearchBox" Margin="30,14,30,24" SearchHistoryEnabled="False" Local:EventToCommandBehavior.RoutedEvent="QuerySubmitted" Local:EventToCommandBehavior.Command="{Binding SearchCommand}" />
                </StackPanel>
            </Popup>

            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup>
                    <VisualState x:Name="Width500">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="AirCommands" Storyboard.TargetProperty="(Grid.Column)">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="AirCommands" Storyboard.TargetProperty="(Grid.Row)">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Width920" />
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        </Grid>
    </Grid>
</Local:NavigationView>